<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>列出 MySQL 数据库中的表</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mysql-list-processes.html">« mysql_list_processes</a></li>
      <li style="float: right;"><a href="function.mysql-num-fields.html">mysql_num_fields »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mysql.html">MySQL 函数</a></li>
    <li>列出 MySQL 数据库中的表</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mysql-list-tables" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_list_tables</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_list_tables</span> &mdash; <span class="dc-title">列出 MySQL 数据库中的表</span></p>

 </div>

 <div id="function.mysql-list-tables-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">本函数自 PHP 4.3.0
 起已废弃，并且它和整个<a href="book.mysql.html" class="link">MySQL 扩展</a>自 PHP 7.0.0 开始被移除。
可以选择出于活跃开发中的<a href="book.mysqli.html" class="link">MySQLi</a>或<a href="ref.pdo-mysql.html" class="link">PDO_MySQL</a>扩展来作为替代。
参见<a href="mysqlinfo.api.choosing.html" class="link">MySQL：选择 API</a> 指南
来获取更多信息。用以替代本函数的有：</p>
   <ul class="simplelist">
    <li class="member">SQL Query: <code class="literal">SHOW TABLES FROM dbname</code></li>
   </ul>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.mysql-list-tables-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysql_list_tables</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$database</code></span>, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type">resource</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   列出 MySQL 数据库中的表。
  </p>
  <p class="para">
   此函数已废弃。推荐使用
   <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span> 来执行 SQL <code class="literal">SHOW TABLES
   [FROM db_name] [LIKE &#039;pattern&#039;]</code> 来实现同样的操作。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-list-tables-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">database</code></dt>

     <dd>

      <p class="para">
       数据库名称
      </p>
     </dd>

    
    <dt>

<code class="parameter">link_identifier</code></dt>
<dd>
<p class="para">MySQL
连接。如不指定连接标识，则使用由 <span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span>
最近打开的连接。如果没有找到该连接，会尝试不带参数调用
<span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span>
来创建。如没有找到连接或无法建立连接，则会生成
<strong><code>E_WARNING</code></strong> 级别的错误。</p></dd>


   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-list-tables-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回结果指针 <span class="type">resource</span>  或者在失败时返回 <strong><code>false</code></strong>。
  </p>
  <p class="para">
   可以使用 <span class="function"><a href="function.mysql-tablename.html" class="function">mysql_tablename()</a></span> 函数来遍历该结果指针，或者使用任何针对表操作的函数，类似
   <span class="function"><a href="function.mysql-fetch-array.html" class="function">mysql_fetch_array()</a></span>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mysql-list-tables-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table id="function.mysql-list-tables.changelog" class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.3.7</td>
       <td>
        此函数已废弃。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysql-list-tables-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1773">
    <p><strong>示例 #1 <span class="function"><strong>mysql_list_tables()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dbname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'mysql_dbname'</span><span style="color: #007700">;<br /><br />if&nbsp;(!</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysql_host'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_user'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_password'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;connect&nbsp;to&nbsp;mysql'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SHOW&nbsp;TABLES&nbsp;FROM&nbsp;</span><span style="color: #0000BB">$dbname</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"DB&nbsp;Error,&nbsp;could&nbsp;not&nbsp;list&nbsp;tables\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'MySQL&nbsp;Error:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Table:&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]}</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-list-tables-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    为了向下兼容，可以使用下列已废弃的别名：
    <span class="function"><strong>mysql_listtables()</strong></span>
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-list-tables-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mysql-list-dbs.html" class="function" rel="rdfs-seeAlso">mysql_list_dbs()</a> - 列出 MySQL 服务器中所有的数据库</span></li>
    <li class="member"><span class="function"><a href="function.mysql-tablename.html" class="function" rel="rdfs-seeAlso">mysql_tablename()</a> - 取得表名</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>